/********************************************************
Analyses for Figure 3
***********************************************************/


/**************************************************
Pew/CNN
**************************************************/


/**************************
		Data
**************************/

clear
*change directory to "....\Data\"
*cd 
use "pew_cnn_comb.dta"


/**************************
		Cleaning
Some of the labels are not right due to recoding in R
This fixes matters
**************************/

**Income
label def inc1 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000-99,999" 5 "100,000+"
label values income1 inc1
label var income1 "Income"

label def inc2 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000+"
label values income2 inc2
label var income2 "Income"

**Gender
label def gend 1 "Female" 0 "Male"
label values gender gend
label var gender "Gender"

**Education 
label var educ "Education"
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "Post-BA"
label values educ edu

**Race/Ethnicity
*Remove the 9
recode race_eth (9 = .)
label var race_eth "Race/Ethnicity"
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Other Race"
label values race_eth rac

**Age
label var age "Age"

**Sponsor
encode sponsor, gen(sponsor1)
label var sponsor "Survey Sponsor"

**Year
label var year "Year of Survey"

**Too Extreme
label var too_extreme1 "Parties Too Extreme?"
label def too1 1 "Neither" 2 "One Too Extreme" 3 "Both Too Extreme"
label values too_extreme1  too1

***PID & Ideol Ext
label var pid_ext "PID Extremity"
label def pext 1 "Independent" 2 "Leaner" 3 "Partisan"
label values pid_ext pext

label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Liberal/Conservative" 3 "Very Liberal/Conservative"
label values ideol_ext iext

***Neither
recode too_extreme1 (1 = 1 "Neither Too Extreme")  (2 3 = 0 "One/Both Too Extreme"), gen(te1)

/**************************
	Model and Predictions
**************************/
eststo clear
eststo: gsem (i.too_extreme1 <- i.pid_ext i.ideol_ext i.gender i.race_eth c.age i.income1 i.educ year sponsor1 S[surveyid]@1) [pweight=weight], mlogit
	margins pid_ext ideol_ext, predict(outcome(1.too_extreme1)) saving(probs_1, replace)
	margins pid_ext ideol_ext, predict(outcome(2.too_extreme1)) saving(probs_2, replace)
	margins pid_ext ideol_ext, predict(outcome(3.too_extreme1)) saving(probs_3, replace)
	
*Table
esttab using "table_oa4.rtf", replace onecell se aic bic label nobaselevels unstack b(3) ///
	mtitles("Neither" "One Party" "Both Parties") ///
	title("{\b Table OA4:} Is the Party Sytem Too Extreme? (Pew & CNN)")
	


/**************************************************
Lucid
**************************************************/
clear
use "lucid_coded_all.dta"

/**************************
		Cleaning
Some of the labels are not right 
This fixes that
**************************/


****PID Strength/Extremity
label var pid_ext "PID Extremity"
label def piext 1 "Independent" 2 "Leaner" 3 "Not Very Strong Partisan" 4 "Strong Partisan"
label values pid_ext piext

label var pid_idstr_1 "PID ID Strength"

****Ideology
*Symbolic
label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Closer Lib/Con"  3 "Somewhat Lib/Con" 4 "Very Lib/Con"
label values ideol_ext iext

****Issue Consistency
label var op_ideol_cons "Issue Consistency"

*Operational
label var op_ideol "Operational Ideology"

****Political Knowledge
label var knowl_sum "Political Knowledge"

****Opinionation
label var opinionation "Opinionation"

****Demographics
*Age
label var age "Age"

*Gender
label var gender "Gender"

*Race
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Asian" 5 "Other Race"
label values race_eth rac
label var race_eth "Race/Ethnicity"

*Education
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "BA+"
label values educ edu

*Income
label var house_income "Income"

*Weight
label var weight "Raked Survey Weight"

*Too Extreme
label var too_extreme_1 "Parties Too Extreme?"
label def tooext 1 "Neither Party" 2 "One Party" 3 "Both Parties"
label values too_extreme_1 tooext

*Perceived Policy Distance
gen ppd = abs(abs(self_ideol-dem_ideol)-abs(self_ideol-rep_ideol))
label var ppd "Perceived Policy Distance"

********************/

***Analyses
eststo clear
eststo: mlogit too_extreme_1 c.pid_idstr_all i.ideol_ext op_ideol_cons ppd knowl_sum opinionation c.age house_income i.gender i.race_eth i.educ , base(1)
		
		*Probabilities
			margins ideol_ext, saving(lucid_sym, replace)
			margins, at(op_ideol_cons=(0(1)5)) saving(lucid_op, replace)
			margins, at(ppd=(0(1)6)) saving(lucid_ppd, replace)	
			margins, at(pid_idstr_all=(1(1)4)) saving(lucid_pid, replace)
		
*Table
esttab using "table_oa5.rtf", replace onecell se bic label nobaselevels unstack ///
	title("{\b Table OA5:} Is the Party Sytem Too Extreme? (Lucid)") pr2
	

	


	